package com.feng.springboothelloworld.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class Logincontroller {
    @RequestMapping("login")
    public String login(@RequestParam("username")String username,
                        @RequestParam("password")String password,
                        Model model, HttpSession session){
        if(username!=null&&"user".equals(password)) {
            model.addAttribute("msg",null);
            session.setAttribute("loginuser",username);
            return "redirect:/main.html";
        }
        else {
            session.setAttribute("loginuser",null);
            model.addAttribute("msg","用户名或者密码错误!");
            return "index";
        }
    }
    @RequestMapping("signout")
    public String signout(HttpSession session){
        session.invalidate();
        return "index";
    }
}
